package cn.zwxky.android.staff.My;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ExpandableListView;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.Permission;
import cn.zwxky.android.staff.Utils.URLString;

/**
 * Created by Administrator on 2017/3/28 0028.
 */
@ContentView(R.layout.aty_saddress_book)
public class SaddressBookActivity extends LsfbActivity {

    /**
     * 二级列表
     */
    @ViewInject(R.id.aty_addpunishment_listview)
    private ExpandableListView listView;

    private List<TellistBean.ListBean> mList;

    private TellistAdapter adapter;

    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "员工通讯录");
        Permission permission = new Permission(this);
        permission.GetcallPermission();

        mList=new ArrayList<>();
        adapter = new TellistAdapter(this, mList);
        listView.setAdapter(adapter);

        listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {

                return true;
            }
        });
        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

                return false;
            }
        });

    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        getData();
    }

    public void getData() {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        new BaseInternet().getData_Get(URLString.TELLIST, hashMap, TellistBean.class, new TellistEvent<TellistBean>(), true, true);
    }

    @EventAnnotation
    public void TellistEvent(TellistEvent<TellistBean> event) {
        switch (event.getCode()) {
            case 200:
                mList.clear();
                mList.addAll(event.getData().getList());
                if (mList.size() > 0) {
                    for (int i=0;i<mList.size();i++)
                    listView.expandGroup(i);
                }
                adapter.notifyDataSetChanged();
                break;
            default:
                SN.SnackShow(listView, event.getMsg());
                break;
        }
    }

    @EventAnnotation
    public void TellClickEvent(TellClickEvent event){
        startActivity(new Intent(
                "android.intent.action.CALL", Uri.parse("tel:"
                + event.getData())));
    }

}
